const fileModel = require('../models/files.model')
const logger = require('../utils/logger')
class FileService {
  files = fileModel
  async findAll (query = {}) {
    let ret = await this.files.find(query)
    return ret
  }
  async addOne (files) {
    const ret = []
    for (let file of Object.values(files)) {
      let model = await this.files.create({
        name: file.name,
        path: file.path
      })
      ret.push(model)
    }
    logger.info('files created ', ret)
    return ret
  }
  deleteOne (id) {
    return this.files.findOneAndUpdate({ _id: id }, { deleted: true })
  }
}

module.exports = FileService